# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/29 下午6:26
 @Author  : tgy
 
"""
import threading
import time
import pickle

class CountDown:

    def __init__(self, n):
        ...
        self.n = n
        self.thread = threading.Thread(target=self.run)
        self.thread.daemon = False


    def start(self):
        self.thread.start()

    def run(self):
        ...
        while self.n > 0:
            print('count donwn {}'.format(self.n))
            self.n -= 1
            time.sleep(1)

    def __getstate__(self):
        ...
        return self.n

    def __setstate__(self, state):
        print(self.__dict__)
        self.__init__(state)



if __name__ == '__main__':
    ...
    count_down = CountDown(5)
    # count_down.start()
    save_cd = pickle.dumps(count_down)
    print(save_cd)
    cd = pickle.loads(save_cd)
    cd.start()
    print(cd.__dict__)